#include <stdio.h>
#include <string.h>

void reverse(char s[]);
void itoa(int n, char s[], int b);

char out[1000];

int main()
{
    int input, b;
    input = -1688;
    b = 16;

    itoa(input, out, b);

    printf("input = %d, base = %d, out = %s\n", input, b, out);

    return 0;
}


void reverse(char s[])
{
    int c, i, j;
    for (i = 0, j = strlen(s) - 1; i < j; i++, j--)
    {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

void itoa(int n, char s[], int b)
{
    int i, sign;
    unsigned int t;
    char bit; 

    if((sign = n) < 0)
        t = -n;
    else
    {
        t = n;
    }
    
    i = 0;
    do{
        bit = t % b;
        if (bit >= 10)
            s[i++] = t % b - 10 + 'A';
        else
            s[i++] = t % b + '0';
    } while ((t /= b) > 0);

    if(sign < 0)
        s[i++] = '-';
    
    s[i] = '\0';
    reverse(s);
}